import { resetRouter, routes } from "@/router";
import { defineStore } from "pinia";
import { ref, type Ref } from "vue";
import type { RouteRecordRaw } from "vue-router";

interface MenuStore {
  menuList: Ref<RouteRecordRaw[]>
  setMenuList: (filterRoutes: RouteRecordRaw[]) => void
}

export const useMenuStore = defineStore("hm-menu", (): MenuStore => {
  // pnpm 的类型报错，yarn 的类型不报错
  const menuList = ref<RouteRecordRaw[]>([...routes])
  const setMenuList = (filterRoutes: RouteRecordRaw[]) => {
    menuList.value = [...menuList.value, ...filterRoutes];

    const clearMenuList = ()=>{
      // 重置左侧菜单
      menuList.value = [...routes];
      // 重置路由系统
      resetRouter();
    }
    return { menuList, setMenuList, clearMenuList };
  };
  return { menuList, setMenuList };
});

